home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1997 December / MACPOWER-1997-12.ISO.7z / MACPOWER-1997-12.ISO / AMUG / PROGRAMMING / Raven 1.2.sit / Raven 1.2 / Source / Foundation / Broadcaster / ZBroadcaster.inc < prev    next >
Text File  |  1997-08-31  |  2KB  |  76 lines

  1. /*
  2.  *  File:       ZBroadcaster.inc
  3.  *  Summary:    Mixin class allowing an object to broadcast to one or more listeners.
  4.  *  Written by: Jesse Jones
  5.  *
  6.  *  Copyright ゥ 1996-1997 Jesse Jones. 
  7.  *    For conditions of distribution and use, see copyright notice in ZTypes.h  
  8.  *
  9.  *  Change History (most recent first):
  10.  *
  11.  *         <2>     8/30/97    JDJ        Broadcast no longer stuffs message
  12.  *                                    in a member.
  13.  *         <1>     1/17/96    JDJ        Created.
  14.  */
  15.  
  16. #include <ZDebug.h>
  17.  
  18.  
  19. //---------------------------------------------------------------
  20. //
  21. // MBroadcaster::~MBroadcaster
  22. //
  23. //---------------------------------------------------------------
  24. template <class MESSAGE>
  25. MBroadcaster<MESSAGE>::~MBroadcaster()
  26. {
  27. }
  28.  
  29.     
  30. //---------------------------------------------------------------
  31. //
  32. // MBroadcaster::MBroadcaster ()
  33. //
  34. //---------------------------------------------------------------
  35. template <class MESSAGE>
  36. MBroadcaster<MESSAGE>::MBroadcaster()
  37. {
  38. }
  39.  
  40.  
  41. //---------------------------------------------------------------
  42. //
  43. // MBroadcaster::Broadcast
  44. //
  45. //---------------------------------------------------------------
  46. template <class MESSAGE>
  47. void MBroadcaster<MESSAGE>::Broadcast(const MESSAGE& message) const
  48. {        
  49.     this->DoBroadcasting(&message);
  50. }
  51.  
  52.  
  53. //---------------------------------------------------------------
  54. //
  55. // MBroadcaster::DoBroadcast
  56. //
  57. // All of this casting is kind of gross, but it allows us to put
  58. // all the list code in a non-template base class. This can really
  59. // add up since broadcasters are often used with weird types.
  60. //
  61. //---------------------------------------------------------------
  62. template <class MESSAGE>
  63. void MBroadcaster<MESSAGE>::DoBroadcast(MBaseListener* theListener, const void* theMessage) const
  64. {    
  65.     MListener<MESSAGE>* listener = dynamic_cast<MListener<MESSAGE>*>(theListener);
  66.     ASSERT(theListener != nil);
  67.     ASSERT(listener != nil);
  68.     
  69.     const MESSAGE* message = reinterpret_cast<const MESSAGE*>(theMessage);
  70.     ASSERT(message != nil);
  71.  
  72.     listener->OnBroadcast(*message);
  73. }
  74.  
  75.  
  76.